import { baseRequestClient } from './request';

export interface ConsignmentItem {
  id: string;
  name: string;
  description: string;
  price: number;
  contactTel: string;
  image: string[];
}

export interface ConsignmentListRes {
  code: number;
  data: ConsignmentItem[];
  message: string;
  status: boolean;
  success: boolean;
  timestamp: number;
}

/**
 * 获取个人寄售列表（GET /consignment/list）
 */
export async function getConsignmentList() {
  const res = await baseRequestClient.get<ConsignmentListRes>('/consignment/list');
  return res?.data;
}

/** 新增个人寄售入参 */
export interface AddConsignmentPayload {
  name: string;
  description: string;
  price: number;
  contactTel: string;
  image: string[];
}

/**
 * 新增个人寄售（POST /consignment/add）
 */
export async function addConsignment(payload: AddConsignmentPayload) {
  const res = await baseRequestClient.post('/consignment/add', payload);
  return res?.data;
}

/** 更新个人寄售入参 */
export interface UpdateConsignmentPayload extends AddConsignmentPayload {
  id: string;
}

/**
 * 更新个人寄售（POST /consignment/update）
 */
export async function updateConsignment(payload: UpdateConsignmentPayload) {
  const res = await baseRequestClient.post('/consignment/update', payload);
  return res?.data;
}

/**
 * 删除个人寄售（DELETE /consignment/{id}）
 */
export async function deleteConsignment(id: string) {
  const res = await baseRequestClient.delete(`/consignment/${id}`);
  return res?.data;
}